dofile("StylusBox2.lua")
dofile("libColor.lua")

CheckBox = {

	new = function (scr, x, y, txt, type, c1)
		local x2 = x+8
		local y2 = y+8
		local stxwx = x+13
		local stxwy = y
		local x3 = stxwx+string.len(txt)*6
		local c2 = c_black
		local c3 = c_white
		local isChecked = false
		
		if c1 == nil then c1 = c_white end
		
		local draw = function (self)
		
		screen.print (scr, stxwx, stxwy, txt)
		screen.drawFillRect (scr, x, y, x2, y2, c2)
		screen.drawRect (scr, x, y, x2, y2, c_white)
		
		if isChecked then
			if type == 'crossInBox' then
				screen.print (scr, x+1, y, "/", c1)
				screen.print (scr, x, y, "\\", c1)
				screen.drawFillRect (scr, x+1, y2-2, x+2, y2-1, c1)
				screen.drawFillRect (scr, x2-1, y2-2, x2-2, y2-1, c1)
			elseif type == 'vInBox' then
				screen.print (scr, x+1, y+1, "", c1)
			elseif type == "fillInBox" then
				c2 = c1
			else
				c2 = c_black
			end
		end
		
		if StylusBox.simplePressed (x, y, x3, y2, Stylus.X, Stylus.Y) and not isChecked then
			c3 = c_black
			isChecked = true
		elseif StylusBox.simplePressed (x, y, x3, y2, Stylus.X, Stylus.Y) and isChecked then
			c2 = c_black
			c3 = c_white
			isChecked = false
		end
		
		--screen.print (SCREEN_UP, 5, 5, Stylus.X)
		--screen.print (SCREEN_UP, 5, 15, Stylus.Y)
		--screen.print (SCREEN_UP, 5, 25, tostring(isChecked))
	end
		
		local isChecked = function (self)
			return isChecked
		end
		
		local clear = function (self)
			self = nil
		end
		 
		return{
			draw = draw,
			isChecked = isChecked,
			clear = clear
		}
	end
}
